package org.example.controller;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.example.Result;
import org.example.mapper.UserMapper;
import org.example.sso.LoginApi;
import org.example.sso.model.entity.UserDO;
import org.example.utils.Opts;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
//@RequestMapping("/feignApi")
//@RequestMapping("/sso")
public class LoginApiController implements LoginApi {

    private final UserMapper userMapper;

    @Override
    public Result<String> getUser(String username) {
        List<UserDO> users = userMapper.selectList(new LambdaQueryWrapper<>(UserDO.class).eq(UserDO::getUserName, username));
        return Opts.of(users).isPresent() ? Result.success(JSONUtil.toJsonStr(users.get(0))) : Result.error(700, "用户不存在");
    }
}
